

const host="http://localhost:8000"
function btnAdd(){
    console.log("狗");
    
    location.href='./addOrEite.html'
}
function btnEdit(id){
    location.href='./addOrEite.html?id='+id
}
function btnDit(id){
    if(confirm('巴巴博一')){
        axios.delete(`${host}/blogs/${id}`).then((res)=>{
            console.log(res);
            if(res.data.code===1000){
               let tr=document.querySelector(`.blog${id}`)
               tr.remove()
            }else{
                confirm(`${data.msg}`)
            }
        }
    )
    }

}
function btnSave(){
let id =new URLSearchParams(location.search).get('id')||0;
let title =$('input[name=title]').val();
let author=$('input[name=author]').val();
title =title.trim()
author=author.trim()
let obj={
    title,author
} ;
if(id>0){
     axios.put(`${host}/blogs/${id}`,obj).then((res)=>{
        if(res.data.code===1000){
            location.href='./index.html'
        }else{
            confirm(res.data.msg)
        }
     });
}else{
     axios.post(`${host}/blogs`,obj).then((res)=>{
        if(res.data.code===1000){
            location.href='./index.html'
        }else{
            confirm(res.data.msg)
        }
     })
}
}
function btnQx(){
    location.href='./index.html'

}
function btnFn(){
    let keyword=$('input[name=keyword]').val()
    axios.get(`${host}/blogs?keyword=${keyword}`).then((res)=>{
        
        $('tr[class^=blog]').remove()
        res.data.data.forEach(item=>{
            let html=`
            <tr class="blog"${item.id}">
            <td>${item.id}</td>
             <td>${item.title}</td>
              <td>${item.author}</td>
                <td>
                <input rype="button" value="编辑"
                onclick="btnEdit(${item.id})>
                 <input rype="button" value="编辑"
                onclick="btnDel(${item.id})>
                </td>
                </tr>

            `;
            $('tbody').append(html)
        }

        )

    
    })
}